package ustc.running.ui;

import ustc.running.R;
import ustc.running.data.SoftwareData;
import ustc.running.util.MyHandler;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.iflytek.speech.SpeechUtility;
import com.umeng.analytics.MobclickAgent;

/**
 * 欢迎页面
 * @author 李跃东
 * @mail androiddevelop@qq.com
 * @date 2013-11-7
 */
public class WelcomeUi extends Activity{
	private MyHandler handler;

	protected void onCreate(Bundle paramBundle){
		super.onCreate(paramBundle);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.welcome_ui);

		//注册统计组件
		MobclickAgent.updateOnlineConfig(this);

		RelativeLayout relativeLayout=(RelativeLayout)findViewById(R.id.welcome_page);
		relativeLayout.startAnimation(AnimationUtils.loadAnimation(this, R.anim.alpha));

		TextView tv=(TextView)findViewById(R.id.version);
		tv.setText(tv.getText().toString()+SoftwareData.VERSION);

		handler = new MyHandler()
		{
			public void handleMessage(Message paramAnonymousMessage)
			{
				super.handleMessage(paramAnonymousMessage);
				WelcomeUi.this.toLogin();
				WelcomeUi.this.finish();
			}
		};

		new Thread(){
			public void run(){
				try{
					SpeechUtility.getUtility(WelcomeUi.this).setAppid("527c9b79");
					Thread.sleep(2000);
					WelcomeUi.this.handler.sendEmptyMessage(0);
				}
				catch (InterruptedException localInterruptedException){
					localInterruptedException.printStackTrace();
				}
			}
		}.start();
	}

	/**
	 * 登录
	 */
	private void toLogin(){
		startActivity(new Intent(this, MainUi.class));
	}

	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}
	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

}